﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DemeGo
{
    /// <summary>
    /// 块的状态
    /// </summary>
    enum BlockStatus
    {
        Blank = 0,
        J1 = 1,
        J2 = 2,
        J3 = 3,
        J4 = 4,
        Q1 = 5,
        Q2 = 6,
        Q3 = 7,
        Q4 = 8
    }



    /// <summary>
    /// 块对象
    /// </summary>
    class Block
    {
        public BlockStatus Status { get; set; }


        //背面是一种状态
        public bool IsBack { get; set; }


        /// <summary>
        /// 矩阵坐标
        /// </summary>
        public Point Point { set; get; }



        /// <summary>
        /// 
        /// </summary>
        /// <param name="x">矩阵x</param>
        /// <param name="y">矩阵y</param>
        public Block(int x, int y, BlockStatus status)
        {
            //初始化状态为背面
            IsBack = true;
            Point = new Point(x, y);
            Status = status;
        }


        /// <summary>
        /// 画出当前格子
        /// </summary>
        /// <param name="g">绘图句柄</param>
        /// <param name="rec">当前block的rectan</param>
        public void Draw(Graphics g, Rectangle rec)
        {
            if (IsBack)
            {
                g.DrawImage(Properties.Resources.back, rec);
                return;
            }
            switch (Status)
            {
                case BlockStatus.Q1:
                    g.DrawImage(Properties.Resources.Q1, rec);
                    break;
                case BlockStatus.Q2:
                    g.DrawImage(Properties.Resources.Q2, rec);
                    break;
                case BlockStatus.Q3:
                    g.DrawImage(Properties.Resources.Q3, rec);
                    break;
                case BlockStatus.Q4:
                    g.DrawImage(Properties.Resources.Q4, rec);
                    break;
                case BlockStatus.J1:
                    g.DrawImage(Properties.Resources.J1, rec);
                    break;
                case BlockStatus.J2:
                    g.DrawImage(Properties.Resources.J2, rec);
                    break;
                case BlockStatus.J3:
                    g.DrawImage(Properties.Resources.J3, rec);
                    break;
                case BlockStatus.J4:
                    g.DrawImage(Properties.Resources.J4, rec);
                    break;
            }
        }


        /// <summary>
        /// 处理鼠标点击，改变当前块的状态
        /// </summary>
        public void MouseDown()
        {
            IsBack = false;
            //点击之后舍弃背面状态
        }
    }
}

